package cn.nange.cmfz.controller;

import cn.nange.cmfz.entity.AdminLog;
import cn.nange.cmfz.service.AdminLogService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("logAdmin")
public class AdminLogController {

    @Autowired
    private AdminLogService logAdminService;

    @ResponseBody
    @RequestMapping("del")
    public Map delete(int[] id) {
        HashMap map = new HashMap();
        try {
            for (int i = 0; i < id.length; i++) {
                logAdminService.del(id[i]);
                System.out.println(id[i]);
                map.put("isDelete", true);
            }

        } catch (Exception e) {
            e.printStackTrace();
            map.put("isDelete", false);
        }
        return map;
    }

    @ResponseBody
    @RequestMapping("show")
    public Map show(Integer page, Integer limit) {

        PageInfo<AdminLog> show = logAdminService.show(page, limit);
        HashMap map = new HashMap();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", show.getTotal());
        map.put("data", show.getList());
        return map;
    }
}
